from odoo import models, fields, api, _
from odoo.exceptions import UserError, ValidationError


class Product(models.Model):
    _inherit = 'product.product'

    def write(self, vals):
        if isinstance(vals, list):
            for rec in vals:
                self.check_group_fields(rec)
        else:
            self.check_group_fields(vals)
        return super().write(vals)

    def check_group_fields(self, vals):
        if 'name' in vals:
            if not self.env.user.has_group('base.group_system') and self.name != 'new':
                raise UserError(_('Non-administrators cannot change the Chinese description of the product'))
        if 'default_code' in vals:
            if not self.env.user.has_group('base.group_system') and self.default_code:
                raise UserError(_('Non-administrators cannot change the default code of the product'))
